import jieba

txt= open("test.txt", "rb")
content = txt.read()

words = jieba.lcut(content)
result = {}

for word in words:
    if len(word) > 1:
        result[word] = result.get(word, 0) + 1

sorted_result = sorted(result.items(), key=lambda x: x[1], reverse=True)[:5]

for word, count in sorted_result:
    print("{}:{}".format(word, count))
with open("output.txt","w")as f:
    for word, count in sorted_result:
        f.write(f"{word}:{count}\n")
